/*
 * @LastEditors: yuSeen
 * @LastEditTime: 2022-01-01 11:15:26
 * 天凉好个秋
 */

import { defineStore } from "pinia";
import { useLocalStorage } from '@/hooks/localStorage/useLocalStorage'
import {
  DisplayModeEnmu,
  LangEnmu,
  ISettingStore,
} from "@/types/store/settingStoreType";
const { getStorageItem, setStorageItem } = useLocalStorage()

// 设置
export const useSettingStore = defineStore({
  id: "setting",
  state: (): ISettingStore => ({
    lang: getStorageItem("lang") || LangEnmu.ZH_CN,
    displayMode: getStorageItem("displayMode") || DisplayModeEnmu.LIGHT,
    theme: getStorageItem("themeColor") || "#fd544e",
  }),
  getters: {
    // 当前是否处于暗色模式
    isDark(): boolean {
      return this.displayMode === DisplayModeEnmu.DARK
    }
  },
  actions: {
    //   设置语言
    setLang(lang: LangEnmu) {
      this.lang = lang;
     setStorageItem("lang", lang);
    },
    //   设置显示模式
    setDisplayMode(mode: DisplayModeEnmu) {
      this.displayMode = mode;
     setStorageItem("displayMode", mode);
    },
    //   设置主题
    setTheme(theme: string) {
      this.theme = theme;
     setStorageItem("themeColor", theme);
    },
  },
});
